package com.xd.clap.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xd.clap.entity.Feedback;
import com.xd.clap.entity.response.Result;
import com.xd.clap.mapper.FeedbackMapper;
import com.xd.clap.services.FeedbackService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class FeedbackServiceImpl implements FeedbackService {
    @Resource
    private FeedbackMapper fm;

    @Override
    public Result getFeedbackList() {
        QueryWrapper<Feedback> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time");
        List<Feedback> suggestionList = fm.selectList(queryWrapper);
        return Result.success(suggestionList, "加载成功！");
    }

    @Override
    public Result saveFeedback(Feedback feedback) {
        feedback.setCreateTime(new Date());
        int insert = fm.insert(feedback);
        if (insert < 1) {
            return Result.fail(0, "反馈失败！");
        }
        return Result.success(insert, "反馈成功！");
    }

    @Override
    public Result deleteFeedback(int id) {
        int delete = fm.deleteById(id);
        if (delete < 1) {
            return Result.fail(0, "删除失败！");
        }
        return Result.success(delete, "删除成功！");
    }

}
